package auth

import (
	"beergo/app/admin/conf"
	controller "beergo/app/admin/controller"
	"beergo/app/sys/elog"
	"beergo/conf/const/code"
	"errors"
	"github.com/beego/beego/v2/server/web"
)

type AdminUserCustomController struct {
	controller.AdminBaseController
}

func init() {
	web.Router(conf.UrlPrefixAdmin + "/password", 		&AdminUserCustomController{}, "*:PasswordAction")
}

func (this *AdminUserCustomController) PasswordAction() {
	println("test")
	old:=this.GetParamString("old")
	newPass:=this.GetParamString("new")
	ag:=this.GetParamString("ag")
	if newPass != ag{
		this.StopError(code.Error,"两次输入的密码不一致","")
	}

	user:=this.GetUser()
	if user.Password != old {
		this.StopError(code.Error,"密码错误","")
	}
	e:=errors.New("test")
	elog.Add(e)
	user.Password = newPass
	_,err:=user.Save()
	this.AnaliseErrors(err)
	this.ReturnSuccess("修改成功","")
}
